<template>
	<view class="page">
		<view class="header">
			<view class="header-1">
				<u-icon name="arrow-leftward" color="323233" size="18" @click="toGoBack()" />
			</view>
			<view class="header-2">
				<image src="/static/logo.png"></image>
				教育培训系统
			</view>
			<view class="header-3"></view>
		</view>
		<view class="content">
			<view class="title">证书邮寄地址</view>
			<u-form labelPosition="left" :model="registForm" :rules="rules" :errorType="errorType" ref="uForm" labelWidth="100">
				<view class="register-basic">
					<u-form-item label="收件人姓名" prop="recipientUserName">
						<u--input :readonly="disabled" placeholder="请输入收件人姓名" type="text" v-model="registForm.recipientUserName" border="none"></u--input>
					</u-form-item>
				</view>
				<view class="register-basic">
					<u-form-item label="收件人电话" prop="recipientUserPhone">
						<u--input :readonly="disabled" placeholder="请输入收件人电话" type="text" v-model="registForm.recipientUserPhone" border="none"></u--input>
					</u-form-item>
				</view>
				<view class="register-basic">
					<u-form-item label="邮寄地址" prop="recipientUserAdress">
						<u--input :readonly="disabled" placeholder="请输入邮寄地址" type="text" v-model="registForm.recipientUserAdress" border="none"></u--input>
					</u-form-item>
				</view>
				<view class="register-basic">
					<u-form-item label="获取人姓名" prop="certUserName">
						<u--input :readonly="disabled" placeholder="请输入获取人姓名" type="text" v-model="registForm.certUserName" border="none"></u--input>
					</u-form-item>
				</view>
				<view class="register-basic">
					<u-form-item label="获取单位名称" prop="certBy">
						<u--input :readonly="disabled" placeholder="请输入获取单位名称" type="text" v-model="registForm.certBy" border="none"></u--input>
					</u-form-item>
				</view>
				<view class="sm">扫描付款二维码</view>
				<view class="register-basic">
					<view class="tc">
						<image src="../../static/index/pay.png" style="width: 180px;" mode="widthFix"></image>
					</view>
				</view>
				<view class="reg-btn flex">
					<u-button class="btn-submit" shape="circle" :disabled="disabled" @click="cancalSubmit">取 消</u-button>
					<u-button class="btn-submit" shape="circle" type="primary" :loading="loading" :disabled="disabled" @click="formSubmit">已填写已付款</u-button>
				</view>
			</u-form>
		</view>
	</view>
</template>

<script>
	import { temsCertUserSimple, certRecordInfo } from '@/api/cert'
	export default {
		data() {
			return {
				loading: false,
				disabled: false,
				registForm: {
					id: '',
					resourceId: '',
					resourceName: '',
					recipientUserName: '',
					recipientUserPhone: '',
					recipientUserAdress: '',
					certUserName: '',
					certBy: '',
					enabledMark: 0,
					lastModifyUserId: '',
					lastModifyTime: ''
				},
				rules: {
					recipientUserName: [
					{
						required: true,
						message: "请输入邮件地址收件人姓名",
						trigger: "blur",
					},
					],
					recipientUserPhone: [
					{
						required: true,
						message: "请输入收件人电话",
						trigger: "blur",
					},
					],
					recipientUserAdress: [
					{
						required: true,
						message: "请输入邮寄地址",
						trigger: "blur",
					},
					],
					certUserName: [
					{
						required: true,
						message: "请输入证书获取人姓名",
						trigger: "blur",
					},
					],
					certBy: [
					{
						required: true,
						message: "请输入证书获取单位名称",
						trigger: "blur",
					},
					]
				},
				errorType: 'toast',
			}
		},
		onLoad(e) {
			this.registForm.resourceId = e.id;
			certRecordInfo(e.id).then(res => {
				if (res.code == 200 && res.data) {
					this.disabled = true;
					this.registForm = res.data;
				}
			})
		},
		methods: {
			toGoBack() {
				uni.navigateBack({
					delta: 1
				})
			},
			cancalSubmit() {
				uni.reLaunch({
					url: '/pages/index/index'
				});
			},
			formSubmit() {
				if (this.loading) return;
				this.$refs.uForm.validate().then(res => {
					this.loading = true;
					let data = this.registForm;
					temsCertUserSimple(data).then(res => {
						if (res.code == 200) {
							uni.showModal({
								title: '提交成功',
								icon: 'success'
							});
							setTimeout(() => {
								uni.reLaunch({
									url: '/pages/index/index'
								});
							},500)
						}
					})
				}).catch(errors => {
					this.loading = false;
				})
			},
			
		}
	}
</script>

<style lang="scss" scoped>
	page {
		background-color: #F6F8FC;
	}
	.page {
		margin: 0;
		padding: 0;
		width: 100%;
		height: 100vh;
		display: flex;
		flex-direction: column;
		align-items: center;
		position: relative;
		.header {
			width: 100%;
			height: 88rpx;
			line-height: 88rpx;
			background-color: #fff;
			display: flex;
			.header-1 {
				margin: 30rpx 0 0 38rpx;
				justify-content: center;
				align-items: center;
			}
			.header-2 {
				flex: 10;
				text-align: center;
				display: flex;
				justify-content: center;
				align-items: center;
				image {
					width: 48rpx;
					height: 48rpx;
					margin-right: 16rpx;
				}
			}
			.header-3 {
				flex: 1;
			}
		}
	}
	.content {
		width: 92%;
	}
	.title {
		font-size: 16px;
		text-align: left;
		margin: 20px 0;
	}
	.register-basic {
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
		padding: 0 32rpx;
	}
	.reg-btn {
		width: 100%;
		border-top: 1px solid #E5E5E5;
		background-color: #fff;
		padding: 10px;
		position: fixed;
		bottom: 0;
		left: 0;
		margin-top: 50rpx;
		box-sizing: border-box;
	}
	.reg-btn button{
		width: 100%;
	}
	.tc {
		text-align: center;
	}
	.sm {
		background-color: #F6F8FC;
		margin-top: 10px;
		margin-bottom: 10px;
	}
</style>
